package com.zz.hhbl.interceptor

import com.zz.framework.core.utils.XPreference
import com.zz.hhbl.config.GlobalCache
import okhttp3.Interceptor

object CookieInterceptor {

    // 解析 cookie, 并存储
    var cookie by XPreference("cookie", "")

    // cookie 拦截器 获取 cookie (自动登录时候需要用到)
    fun builder(): Interceptor {
        return Interceptor { chain ->
            // 获取 请求
            val request = chain.request()
            val requestUrl = request.url.toString()
            val builder = request.newBuilder()
            if (cookie.isNotEmpty()) {
                builder.addHeader("Cookie", cookie)
            }
            builder.addHeader("Cookie","UUUUU=${GlobalCache.getToken()}" )
            return@Interceptor chain.proceed(builder.build())
        }
    }
}